package ljt.smsplatform.strategy.util;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.ConcurrentHashMap;

@Component("gatewayQueue")
public class GatewayQueue {
    @Resource
    RabbitAdmin rabbitAdmin;

    private static ConcurrentHashMap<String, Integer> gatewayMap = new ConcurrentHashMap();

    public synchronized void createQueue(String queueName) {
        Integer flag = gatewayMap.get(queueName);
        if (flag == null) {
            Queue queue = new Queue(queueName, true);
            rabbitAdmin.declareQueue(queue);
            gatewayMap.put(queueName, 1);
        }
    }
}
